//
//  KLDJDdetViewController.m
//  YaDiuDiu
//
//  Created by 欧洪飞 on 2017/10/27.
//  Copyright © 2017年 jy. All rights reserved.
//

#import "KLDJDdetViewController.h"

#import "KLDjdManViewController.h"
@interface KLDJDdetViewController ()
@property (weak, nonatomic) IBOutlet UIView *view1;
@property (weak, nonatomic) IBOutlet UILabel *labDDH;
@property (weak, nonatomic) IBOutlet UILabel *labOrderTime;
@property (weak, nonatomic) IBOutlet UILabel *labKG;
@property (weak, nonatomic) IBOutlet UILabel *labQHDZ;
@property (weak, nonatomic) IBOutlet UILabel *labPSDZ;
@property (weak, nonatomic) IBOutlet UILabel *labPhone;
@property (weak, nonatomic) IBOutlet UILabel *labRemark;
@property (weak, nonatomic) IBOutlet UIScrollView *sclView;

@property (nonatomic,strong) NSArray *array;//苦力人员
@property (nonatomic,strong) NSDictionary *dic;


@end

@implementation KLDJDdetViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self showNav:@"订单详情"];
    //[self loadUI];
    [self loadData];
    
}

- (void)loadUI{
    NSMutableArray *images = [NSMutableArray array];
    for (NSDictionary *dic in _array) {
        NSString *imgUrl = [NSString stringWithFormat:@"%@%@",[user objectForKey:@"ImageUrl"],[dic objectForKey:@"img"]];
        [images addObject:imgUrl];
    }
    
    for (NSInteger i = 0; i<images.count; i++) {
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(16*(i+1)+60*i, 20, 60, 60)];
        imageView.layer.cornerRadius = 30.0;
        imageView.layer.masksToBounds = YES;
        [imageView sd_setImageWithURL:[NSURL URLWithString:images[i]] placeholderImage:nil];
        [_sclView addSubview:imageView];
        
    }
    
    _labDDH.text = [_dic objectForKey:@"ordernumber"];
    NSString *date = [_dic objectForKey:@"addtime"];
    NSString *time = [self getNewDate:date];
    _labOrderTime.text = time;
    _labKG.text = [NSString stringWithFormat:@"%likg",[[_dic objectForKey:@"weight"] integerValue]];
    _labQHDZ.text = [_dic objectForKey:@"quaddress"];
    _labPSDZ.text = [_dic objectForKey:@"goaddress"];
    _labPhone.text = [_dic objectForKey:@"phone"];
    _labRemark.text = [_dic objectForKey:@"remarks"];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(click)];
    [_sclView addGestureRecognizer:tap];
    _sclView.userInteractionEnabled = YES;
    
    
}

- (void)click{
    KLDjdManViewController *man = [[KLDjdManViewController alloc] init];
    man.array = [NSMutableArray arrayWithArray:_array];
    [self.navigationController pushViewController:man animated:YES];
}

//苦力完成详情
- (void)loadData{
    [SVProgressHUD show];
    [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeBlack];
    NSMutableDictionary *parmas = [NSMutableDictionary dictionary];
    [parmas setObject:_orderId forKey:@"id"];
    [parmas setObject:_merid forKey:@"merchantid"];
    
    NSString *url = [NSString stringWithFormat:@"%@/App/Ordermanage/cooliedetails",urlHead];
    [[AFHTTPSessionManager manager] POST:url parameters:parmas success:^(NSURLSessionDataTask *task, id responseObject) {
        NSLog(@"res:%@",responseObject);
        _array = [[responseObject objectForKey:@"result"] objectForKey:@"delivery"];
        _dic = [[responseObject objectForKey:@"result"] objectForKey:@"list"];
        [self loadUI];
        [SVProgressHUD dismiss];
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        NSLog(@"error:%@",error);
        [SVProgressHUD dismiss];
    }];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
